unit UFrmContafinal;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Wwdbigrd, Grids, Wwdbgrid, Buttons, RXCtrls, ExtCtrls, DBCtrls,
  jpeg;

type
  TFrmContafinal = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Bevel1: TBevel;
    GroupBox3: TGroupBox;
    Edit1: TEdit;
    SpeedButton1: TSpeedButton;
    wwDBGrid1: TwwDBGrid;
    wwDBGrid1IButton: TwwIButton;
    Bevel2: TBevel;
    DBText1: TDBText;
    Label7: TLabel;
    DBText2: TDBText;
    DBText3: TDBText;
    Panel1: TPanel;
    RxLabel1: TRxLabel;
    Panel2: TPanel;
    wwDBGrid2: TwwDBGrid;
    DBText4: TDBText;
    Timer1: TTimer;
    Timer2: TTimer;
    Panel3: TPanel;
    wwDBGrid3: TwwDBGrid;
    Timer3: TTimer;
    Timer4: TTimer;
    Label3: TLabel;
    Bevel3: TBevel;
    Bevel4: TBevel;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    Bevel5: TBevel;
    Bevel6: TBevel;
    Image1: TImage;
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure wwDBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure SpeedButton1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);
    procedure Timer4Timer(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure wwDBGrid2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit1Enter(Sender: TObject);
    procedure wwDBGrid3KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure SpeedButton2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    h , h2, w, w2 : integer;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmContafinal: TFrmContafinal;

implementation
uses modulo;
{$R *.DFM}

procedure TFrmContafinal.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
  var
    vBusca : String;
begin
  Case key of
    VK_Return:
    Begin
       if (Edit1.text = '') then
       begin
          ShowMessage('Digite um nome para pesquisar!');
          Edit1.SetFocus;
          exit;
       end;
       if (Edit1.text <> '') then
       begin
          vBusca:='';
          DMEscola.Qconsultacli.Close;
          DMEscola.Qconsultacli.SQL.Clear;
          DMEscola.Qconsultacli.Sql.Add ('Select * From Clientes');
          DMEscola.Qconsultacli.Sql.Add('WHERE ');
          DMEscola.Qconsultacli.Sql.Add('(Nome like :pNOME) or');
          DMEscola.Qconsultacli.Sql.Add('(NickName like :pNICK)');
          DMEscola.Qconsultacli.ParamByName('pNOME').AsString:='%'+Edit1.text+'%';
          DMEscola.Qconsultacli.ParamByName('pNICK').AsString:='%'+Edit1.text+'%';
          DMEscola.Qconsultacli.open;
          vBusca:=DMEscola.QconsultacliNome.Value;
          If vBusca <> '' then
          begin
             wwDBGrid1.visible:=True;
             wwDBGrid1.setfocus;
          end
          else
          begin
             ShowMessage('Cliente não encontrado efetue a pesquisa novamente '+#13+'ou clique para acesso avulso');
             Edit1.Text := '';
             Edit1.SetFocus;
          end;
       end;
    end;
  end;
end;

procedure TFrmContafinal.wwDBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   case Key of
      VK_Return:
      begin
         Label7.visible := true;
         DBText1.visible := true;
         DMEscola.Qsumvenda.close;
         DMEscola.Qsumvenda.SQL.Clear;
         DMEscola.Qsumvenda.SQL.Add('Select Sum(preco_total) From detalhes_venda_produtos');
         DMEscola.Qsumvenda.SQL.Add('Where cod_cli = :pcli and');
         DMEscola.Qsumvenda.SQL.Add('pago = false');
         DMEscola.Qsumvenda.ParamByName('pcli').AsInteger := StrToInt(DBText4.Field.AsString);
         DMEscola.Qsumvenda.Open;
         DBText2.visible := true;
         DBText4.Visible := true;
         //============
         DMEscola.Qsumacesso.close;
         DMEscola.Qsumacesso.SQL.Clear;
         DMEscola.Qsumacesso.SQL.Add('Select sum(total_acesso) From venda_acesso');
         DMEscola.Qsumacesso.SQL.Add('Where cliente = :pcli2 and');
         DMEscola.Qsumacesso.SQL.Add('pago = false');
         DMEscola.Qsumacesso.ParamByName('pcli2').AsString := DBText1.Field.AsString;
         DMEscola.Qsumacesso.Open;
         DBText3.visible := true;
         RxLabel1.caption := FloatToStr((DbText2.Field.AsCurrency)+(DBText3.Field.AsCurrency));
         BitBtn1.SetFocus;
         wwDBGrid1.Visible := false;
      end;
   end;

end;

procedure TFrmContafinal.SpeedButton1Click(Sender: TObject);
  var
    vBusca : String;
begin
       if (Edit1.text = '') then
       begin
          ShowMessage('Digite um nome para pesquisar!');
          Edit1.SetFocus;
          exit;
       end;
       if (Edit1.text <> '') then
       begin
          vBusca:='';
          DMEscola.Qconsultacli.Close;
          DMEscola.Qconsultacli.SQL.Clear;
          DMEscola.Qconsultacli.Sql.Add ('Select * From Clientes');
          DMEscola.Qconsultacli.Sql.Add('WHERE ');
          DMEscola.Qconsultacli.Sql.Add('(Nome like :pNOME) or');
          DMEscola.Qconsultacli.Sql.Add('(NickName like :pNICK)');
          DMEscola.Qconsultacli.ParamByName('pNOME').AsString:='%'+Edit1.text+'%';
          DMEscola.Qconsultacli.ParamByName('pNICK').AsString:='%'+Edit1.text+'%';
          DMEscola.Qconsultacli.open;
          vBusca:=DMEscola.QconsultacliNome.Value;
          If vBusca <> '' then
          begin
             wwDBGrid1.visible:=True;
             wwDBGrid1.setfocus;
          end
          else
          begin
             ShowMessage('Cliente não encontrado efetue a pesquisa novamente '+#13+'ou clique para acesso avulso');
             Edit1.Text := '';
             Edit1.SetFocus;
          end;
       end;
end;

procedure TFrmContafinal.BitBtn1Click(Sender: TObject);
begin
   if Panel3.visible = true then
      timer4.enabled := true;
   timer1.enabled := true;
   Panel2.visible := true;
   DMEscola.Qdetalhesven.close;
   DMEscola.Qdetalhesven.SQL.Clear;
   DMEscola.Qdetalhesven.SQL.Add('Select * From detalhes_venda_produtos');
   DMEscola.Qdetalhesven.SQL.Add('Where cod_cli = :pcli and');
   DMescola.Qdetalhesven.SQL.Add('pago = false');
   DMEscola.Qdetalhesven.ParamByName('pcli').AsInteger := StrToInt(DBText4.Field.AsString);
   DMescola.Qdetalhesven.Open;
end;

procedure TFrmContafinal.FormShow(Sender: TObject);
begin
   Edit1.SetFocus;
end;

procedure TFrmContafinal.Timer1Timer(Sender: TObject);
begin
   h := h + 5;
   w := w + 20;
   Panel2.height := h;
   Panel2.width := w;
   if w >= 420 then
      timer1.enabled := false;
end;

procedure TFrmContafinal.Timer2Timer(Sender: TObject);
begin
   h := h - 5;
   w := w - 20;
   Panel2.height := h;
   Panel2.width := w;
   if w <= 0 then
      timer2.enabled := false;
end;

procedure TFrmContafinal.BitBtn2Click(Sender: TObject);
begin
   if Panel2.visible = true then
      timer2.enabled := true;
   Panel3.visible := true;
   timer3.enabled := true;
   DMescola.Qacesso.close;
   DMEscola.Qacesso.SQL.Clear;
   DMEscola.Qacesso.SQL.Add('Select * From venda_acesso');
   DMEscola.Qacesso.SQL.Add('Where cliente = :pcli and');
   DMescola.Qacesso.SQL.Add('pago = false');
   DMEscola.Qacesso.ParamByName('pcli').AsString := DBText1.Field.AsString;
   DMEscola.Qacesso.Open;
end;

procedure TFrmContafinal.Timer3Timer(Sender: TObject);
begin
   h2 := h2 + 5;
   w2 := w2 + 20;
   Panel3.Height := h2;
   Panel3.Width := w2;
   if w2 >= 420 then
      timer3.enabled := false;
end;

procedure TFrmContafinal.Timer4Timer(Sender: TObject);
begin
   h2 := h2 - 5;
   w2 := w2 - 20;
   Panel3.Height := h2;
   Panel3.Width := w2;
   if w2 <= 0 then
      timer4.enabled := false;
end;

procedure TFrmContafinal.SpeedButton3Click(Sender: TObject);
begin
   DMEscola.Qdetalhesven.Edit;
   DMEscola.Qdetalhesven.Post;
   DMEscola.Qdetalhesven.Refresh;
   DMEscola.Qacesso.Edit;
   DMEscola.Qacesso.Post;
   DMEscola.Qacesso.Refresh;
//===========
   DMEscola.Qsumvenda.close;
   DMEscola.Qsumvenda.SQL.Clear;
   DMEscola.Qsumvenda.SQL.Add('Select Sum(preco_total) From detalhes_venda_produtos');
   DMEscola.Qsumvenda.SQL.Add('Where cod_cli = :pcli and');
   DMEscola.Qsumvenda.SQL.Add('pago = false');
   DMEscola.Qsumvenda.ParamByName('pcli').AsInteger := StrToInt(DBText4.Field.AsString);
   DMEscola.Qsumvenda.Open;
//============
   DMEscola.Qsumacesso.close;
   DMEscola.Qsumacesso.SQL.Clear;
   DMEscola.Qsumacesso.SQL.Add('Select sum(total_acesso) From venda_acesso');
   DMEscola.Qsumacesso.SQL.Add('Where cliente = :pcli2 and');
   DMEscola.Qsumacesso.SQL.Add('pago = false');
   DMEscola.Qsumacesso.ParamByName('pcli2').AsString := DBText1.Field.AsString;
   DMEscola.Qsumacesso.Open;
   RxLabel1.caption := FloatToStr((DbText2.Field.AsCurrency)+(DBText3.Field.AsCurrency));
end;

procedure TFrmContafinal.wwDBGrid2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   DMEscola.Qdetalhesven.Edit;
   DMEScola.QdetalhesvenDataPGTO.Value := Date;
end;

procedure TFrmContafinal.Edit1Enter(Sender: TObject);
begin
   DBTExt1.Visible := false;
   DBTExt4.Visible := false;
   timer2.enabled := true;
   timer4.enabled := true;
end;

procedure TFrmContafinal.wwDBGrid3KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   DMEscola.Qacesso.Edit;
   DMescola.QacessoDataPGTo.Value := Date;
end;

procedure TFrmContafinal.SpeedButton2Click(Sender: TObject);
begin
   close;
end;

procedure TFrmContafinal.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
   Action := CaFree;
end;

procedure TFrmContafinal.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
   if MessageDlg('Deseja encerrar conta do cliente?', MtConfirmation, [mbyes, mbno], 0) = mrno then
      CanClose := false;
end;

end.
